package com.controller;

import com.entity.Emp;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.validation.Valid;
import java.util.List;

@Controller
public class HomeController {

    @RequestMapping("/index")
    public String index(@Valid Emp emp, BindingResult result) {
        List<FieldError> fieldErrors = result.getFieldErrors();

        for (FieldError fieldError : fieldErrors) {
            System.out.println("field:" + fieldError + " msg:" + fieldError.getDefaultMessage());
        }


        if (result.hasErrors()) {
            //
        } else {
            //调用业务逻辑。


        }

        return "index";
    }
}
